home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / misc / LEDA_gene.lha / LEDA-3.1c-generic / incl / LEDA / leda_window.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-05  |  7.0 KB  |  282 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  leda_window.h
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15. #ifndef LEDA_BASIC_WINDOW_H
  16. #define LEDA_BASIC_WINDOW_H
  17.  
  18. #include <LEDA/impl/x_window.h>
  19.  
  20. typedef double (*draw_func_ptr) (double);
  21. typedef void   (*redraw_func_ptr) ();
  22. typedef void   (*mouse_action_func_ptr) (double,double);
  23.  
  24.  
  25. class color {
  26.  
  27.   int col_index;
  28.  
  29. public:
  30.  
  31.   color(const char*);
  32.   color(int=black);
  33.   operator int() const  { return col_index; }
  34. };
  35.  
  36.  
  37. extern color FG_color;
  38. extern color BG_color;
  39.  
  40.  
  41.  
  42. struct LEDA_WINDOW {
  43.  
  44. Window draw_win;
  45.  
  46. int ref_count;
  47.  
  48. char default_frame_label[128];
  49.  
  50. mouse_action_func_ptr mouse_action;
  51. redraw_func_ptr redraw;
  52.  
  53. int show_coord;
  54.  
  55. // pixel coordinates
  56. int xdots;
  57. int ydots;
  58. int xorigin;
  59. int yorigin;
  60.  
  61. // mouse data
  62. int mouse_key;
  63. int mouse_xpix;
  64. int mouse_ypix;
  65. int mouse_start_xpix;
  66. int mouse_start_ypix;
  67. unsigned long mouse_press_time;
  68. unsigned long mouse_release_time;
  69.  
  70. double mouse_xreal;
  71. double mouse_yreal;
  72. double mouse_last_xreal;
  73. double mouse_last_yreal;
  74. double mouse_start_xreal;
  75. double mouse_start_yreal;
  76.  
  77.  
  78. char* mesg_list[32];
  79. int   mesg_count;
  80.  
  81. //window coordinates
  82. double max_xcoord;
  83. double min_xcoord;
  84. double max_ycoord;
  85. double min_ycoord;
  86. double scaling;
  87.  
  88. //window geomtry
  89. int window_xpos;
  90. int window_ypos;
  91. int window_width;
  92. int window_height;
  93. int grid_mode;
  94. int depth;
  95.  
  96. //window parameters
  97.  
  98. int line_width;
  99. int node_width;
  100. int screen_flush;
  101.  
  102. line_style   line_st;
  103. text_mode    text_mo;
  104. drawing_mode drawing_mo;
  105.  
  106.  
  107. void cursor(void);
  108.  
  109. static int event_handler(LEDA_WINDOW*&,int);
  110.  
  111. static LEDA_WINDOW* window_list[32]; // list of all opened windows
  112. static int count;  // number of opened windows
  113.  
  114. static LEDA_WINDOW*  read_window; 
  115. static LEDA_WINDOW*  active_window; 
  116.  
  117. static void mouse_default_action(double,double);
  118. static void mouse_segment_action(double x, double y) ;
  119. static void mouse_rect_action(double x, double y);
  120. static void mouse_circle_action(double x, double y);
  121. static int screen_width(void);
  122. static int screen_height(void);
  123. static int screen_depth(void);
  124.  
  125.  
  126. protected:
  127.  
  128. int state;
  129.  
  130.  
  131. public:
  132.  
  133. // setting parameters
  134.  
  135. void set_show_coordinates(int x) { show_coord = x; }
  136. void set_redraw(redraw_func_ptr f) { redraw = f; }
  137.  
  138. int  load_text_font(const char* fname);
  139. int  load_bold_font(const char* fname);
  140. int  load_message_font(const char* fname);
  141.  
  142. int          set_font(const char* s);
  143. void         set_grid_mode(int i);
  144. line_style   set_line_style(line_style s);
  145. int          set_line_width(int w);
  146. drawing_mode set_mode(drawing_mode m);
  147. int          set_node_width(int w);
  148. text_mode    set_text_mode(text_mode m);
  149. void         set_frame_label(const char* s);
  150. void         reset_frame_label();
  151. void         set_flush(int b) { screen_flush = b; }
  152. void         set_palette(int c, int r, int g, int b);
  153.  
  154.  
  155. // reading parameters
  156.  
  157. int          get_line_width() { return line_width; }
  158. int          get_node_width() { return node_width; }
  159. int          get_grid_mode()  { return grid_mode; }
  160. line_style   get_line_style() { return line_st;    }
  161. text_mode    get_text_mode()  { return text_mo;    }
  162. drawing_mode get_mode()       { return drawing_mo; }
  163.  
  164. int    mono()  { return depth == 1; }
  165. double xmin()  { return min_xcoord; }
  166. double xmax()  { return max_xcoord; }
  167. double ymin()  { return min_ycoord; }
  168. double ymax()  { return max_ycoord; }
  169. double scale() { return scaling; }
  170.  
  171. int xpos() { return window_xpos; }
  172. int ypos() { return window_ypos; }
  173. int width() { return window_width; }
  174. int height() { return window_height; }
  175.  
  176.  
  177. int xpix(double coord) { return int(xorigin + (coord)*scaling); }
  178. int ypix(double coord) { return int(yorigin - (coord)*scaling); }
  179.  
  180. double pix_num(int p) { return p/scaling; }
  181. double pix_to_real(int p) { return p/scaling; }
  182. int real_to_pix(double d) { return int(d*scaling); }
  183.  
  184. double xreal(int pix)  { return double(pix-xorigin)/scaling; }
  185. double yreal(int pix)  { return double(yorigin-pix)/scaling; }
  186.  
  187.  
  188. void init(double x0, double x1, double y0, int g_mode=0);
  189.  
  190.  
  191. void flush();
  192.  
  193. void open(int w_width, int w_height, int w_xpos, int w_ypos, 
  194.                                                       const char *frame_label);
  195. void close();
  196.  
  197.  LEDA_WINDOW(float width,float height,float xpos,float ypos,
  198.                                                   const char *frame_label = "");
  199.  LEDA_WINDOW(float width,float height, const char *frame_label = "");
  200.  LEDA_WINDOW(const char* frame_label);
  201.  LEDA_WINDOW();
  202.  LEDA_WINDOW(const LEDA_WINDOW&);
  203.  
  204. ~LEDA_WINDOW();
  205.  
  206.  LEDA_WINDOW& operator=(const LEDA_WINDOW&);
  207.  
  208. // events
  209.  
  210. int  read_event(int& k, double& x, double& y);
  211. int  get_event(int& k, double& x, double& y);
  212. void put_back_event();
  213.  
  214.  
  215. // mouse input
  216.  
  217. friend int read_mouse(LEDA_WINDOW*&,double&,double&);
  218.  
  219. int read_mouse_action(mouse_action_func_ptr action, double xstart, double ystart, double& x, double& y);
  220. int read_mouse(int kind, double xstart, double ystart, double& x, double& y);
  221. int get_button(double& x, double& y);
  222.  
  223. unsigned long button_press_time();
  224. unsigned long button_release_time();
  225.  
  226.  
  227. // drawing
  228.  
  229. void draw_pix(double x, double y, int col=black);
  230. void draw_point(double x, double y, int col=black);
  231. void draw_segment(double x1, double y1, double x2, double y2, int col=black);
  232.  
  233. void draw_node(double x0, double y0, int col=black);
  234. void draw_filled_node(double x0, double y0, int col=black);
  235. void draw_text_node(double x0, double y0, char *s, int col=white);
  236. void draw_int_node(double x0, double y0, int i, int col=white);
  237.  
  238. void draw_edge(double x1, double y1, double x2, double y2, int col=black);
  239.  
  240. void draw_circle(double x0, double y0, double r, int col=black);
  241. void draw_filled_circle(double x0, double y0, double r, int col=black);
  242. void draw_ellipse(double x0, double y0, double a, double b, int col=black);
  243. void draw_filled_ellipse(double x0, double y0, double a, double b, int col=black);
  244. void draw_arc(double x0, double y0, double r1, double r2, double start, double angle, int col=black);
  245. void draw_filled_arc(double x0, double y0, double r1, double r2, double start, double angle, int col=black);
  246.  
  247. void draw_polygon(int n, double *xcoord, double *ycoord, int col=black);
  248. void draw_filled_polygon(int n, double *xcoord, double *ycoord, int col=black);
  249. void draw_rectangle(double x1, double y1, double x2, double y2, int col=black);
  250. void draw_filled_rectangle(double x1, double y1, double x2, double y2, int col=black);
  251.  
  252.  
  253. void plot_xy(double x0, double x1, double (*f) (double), int col=black);
  254. void plot_yx(double y0, double y1, double (*f) (double), int col=black);
  255.  
  256. // text
  257.  
  258. void draw_text(double x, double y, const char* s, int col=black);
  259. void draw_ctext(double x, double y, const char* s, int col=black);
  260.  
  261.  
  262. // misc
  263.  
  264. void clear(int col=white);
  265. void message(const char *s);
  266. void del_messages(void);
  267. void copy_rect(double x1, double y1, double x2, double y2, double x, double y);
  268. void insert_bitmap(int width, int height, char* data);
  269.  
  270. };
  271.  
  272.  
  273.  
  274. // some useful functions
  275.  
  276. char* Read_Leda_Bitmap(const char* fname, int& w, int& h) ;
  277.  
  278. void put_back_event();
  279.  
  280. #endif
  281.